﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace iLangl.Model
{
	public class BillingInfoRequestContext : BaseContext
	{
		BillingInfo billingInfo = null;
		public override void SetContext(object context)
		{
			base.SetContext(context);

			if (context is BillingInfo)
			{
				billingInfo = context as BillingInfo;
			}
		}

		public override object GetContext()
		{
			if (billingInfo == null)
				return string.Empty;

			startDocument();
			Write(writer);

			writer.WriteEndElement();
			return endDocument();
		}

		public void Write(XmlWriter writer)
		{
			writer.WriteStartElement("BillingInfo");

			writer.WriteAttributeString("billingId", billingInfo.Id);
			writer.WriteAttributeString("billingCity", billingInfo.BillingCity);
			writer.WriteAttributeString("billingCountry", billingInfo.BillingCountry);
			writer.WriteAttributeString("billingCurrency", billingInfo.BillingCurrency);
			writer.WriteAttributeString("billingEmail", billingInfo.BillingEmail);
			writer.WriteAttributeString("billingFirstName", billingInfo.BillingFirstName);
			writer.WriteAttributeString("billingLastName", billingInfo.BillingLastName);
			writer.WriteAttributeString("billingPostalCode", billingInfo.BillingPostalCode);
			writer.WriteAttributeString("billingStreetAddress", billingInfo.BillingStreetAddress);
			writer.WriteAttributeString("billingStreetAddress2", billingInfo.BillingStreetAddress2);
			writer.WriteAttributeString("billingCompany", billingInfo.Company.Id);
			InitExtendedAttributes(writer, billingInfo);
			InitExtendedElements(writer, billingInfo);
		}
	}
}

